package com.zk.gen;

import org.beetl.sql.core.*;
import org.beetl.sql.core.db.DBStyle;
import org.beetl.sql.core.db.MySqlStyle;
import org.beetl.sql.ext.DebugInterceptor;

public class PojoGen {

    public static void main(String[] args) {
        String mysqlDriver="com.mysql.jdbc.Driver";
        String url="jdbc:mysql://106.12.219.159:3306/heyblog?useUnicode=true&characterEncoding=UTF-8";
        String userName="root";
        String password="root";
        ConnectionSource source=ConnectionSourceHelper.getSimple(mysqlDriver, url, userName, password);
        DBStyle mysql=new MySqlStyle();

        //SQL语句放于classpath的sql目录下
        SQLLoader loader=new ClasspathLoader("/sql");
        //数据库命名和java命名一样，所以采用DefaultNameConversion,还有一个UnderlinedNameConversion下划线风格的
        UnderlinedNameConversion nc=new UnderlinedNameConversion();
        //最后，创建一个SQLManager,DebugInterceptor,不是必须的，但可以通过它查看SQL的执行情况
        SQLManager sqlManager=new SQLManager(mysql, loader,source,nc,new Interceptor[]{new DebugInterceptor()});

        System.out.println("开始生成代码：");
        try {
            sqlManager.genPojoCodeToConsole("discuss");
//            sqlManager.genSQLTemplateToConsole("person");
//            sqlManager.genSQLTemplateToConsole("user");

        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("代码生成结束....");
    }
}
